package com.demo.springcloud.controller;

import com.demo.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author hxg
 * @version 1.0
 * @date 2021/12/28 16:43
 */
@RestController
@RequestMapping("/payment/hystrix")
public class paymentController {
    @Value("${server.port}")
    private String serverPort;

    @Resource
    private PaymentService paymentService;

    @GetMapping("/success/{id}")
    public String paymentSuccess(@PathVariable("id") Long id){
        return paymentService.paymentInfoSuccess(id)+"==="+serverPort;
    }

    @GetMapping("/fail/{id}")
    public String paymentFail(@PathVariable("id") Long id){
        return paymentService.paymentInfoFail(id)+"==="+serverPort;
    }

    //====服务熔断
    @GetMapping("/payment/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id)
    {
        String result = paymentService.paymentCircuitBreaker(id);
        return result;
    }
}
